package com.lx.top.n;

import com.lx.entitys.CovidTopEntity;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: chenjiang
 * @Date: 2021/11/18/21:07
 * @Description:
 */
public class CovidTopNMapper extends Mapper<LongWritable, Text, CovidTopEntity, LongWritable> {
    private CovidTopEntity outKey = new CovidTopEntity();
    LongWritable outValue = new LongWritable();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String values = new String(value.getBytes(), 0, value.getLength(), "GBK");
        String[] fields = values.split(",");
        // 州 县 确诊病例
        outKey.setState(fields[2]);
        outKey.setCounty(fields[1]);
        outKey.setCases(Long.parseLong(fields[fields.length - 2]));
        outValue.set(Long.parseLong(fields[fields.length - 2]));
        context.write(outKey, outValue);
    }
}
